<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>住户审核</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
 	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        body .btn-calss .layui-layer-btn .layui-layer-btn1 {
        	border-color: #2e8ded;
        	background-color: #2e8ded;
        	color: #fff;
        }
         body .btn-calss .layui-layer-btn .layui-layer-btn0 {
         	border-color: #f1f1f1;
        	background-color: #f1f1f1;
        	color: #333;
        } 
        .jqGrid_wrapper{
			*+margin-left:270px;
			
		}      
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
    <div class="jqGrid_wrapper">
        <div id="jqGrid_operation" class="jg-grid">
            <h1>住户审核</h1>
            <div class="jqGrid_operation" id="action"></div>
        </div>
        <table id="jqGrid"></table>
        <div id="jqGrid_paper"></div>
    </div>
</div>
<script>
    $(document).ready(
            function () {

                $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid(
                        {
                            url: "${pageContext.request.contextPath}/admin/tusers_auditList.action?communityId=${communityId}&agtCode=${agtCode}",
                            mtype: 'POST',
                            datatype: "json",
                            height:450,
                            multiselect:false,
                            autowidth: true,
                            shrinkToFit: true,
                            rowNum: 10,
                            rowList: [10, 20, 30],
                            colNames: ['序号', '公司', '小区名称', '楼栋单元房号', '姓名', '手机号','申请时间',
                                       '状态 ', '审核时间', '审核人', '备注 ', '操作'],
                            colModel: [{
                                name: "SID",
                                index: "SID",
                                key: true,
                                hidden: true
                            },{
                                name: 'AGTNAME',
                                index: 'AGTNAME'
                            },{
                                name: 'COMMUNITYNAME',
                                index: 'COMMUNITYNAME'
                            },{
                                name: 'INSTALLUNITID',
                                index: 'INSTALLUNITID',
                                width: 180
                            },{
                                name: 'AUNAME',
                                index: 'AUNAME'
                            },{
                                name: 'TEL',
                                index: 'TEL'
                            },{
                                name: 'CTIME',
                                index: 'CTIME'
                            },{
                                name: "STATUS",
                                index: "STATUS",
                                width: 85,
                                formatter: "select",
                                editoptions: {value: "-1:;0:待审核;1:审核通过;2:审核拒绝;3:候审;"}
                            },{
                                name: 'ATIME',
                                width: 100,
                                index: 'ATIME'
                                
                            },{
                                name: 'AUSERNAME',
                                index: 'AUSERNAME',
                                width: 80,
                                formatter: function (cellvalue, options, rawObject) {
                                 	 if(!cellvalue){
                                        return '';
                                    }else if(cellvalue == '-1'){
                                      	 return '';
                                    }else if(cellvalue.substring(0,2)=='()'){
                                        return cellvalue.substring(2,cellvalue.length);
                                    }else{
                                   	 return cellvalue;
                                    }
                                 }
                            },{
                                name: 'COMM',
                                index: 'COMM'
                                
                            },{
                                name: 'STATUS',
                                index: 'STATUS',
                                width: 160,
                                formatter: function (cellvalue, options, rawObject) {
                                 switch (cellvalue) {
                                     case "0":
                                     case "3":
                                       return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="审核 " onclick="approve('
                                                     + rawObject.SID + ',2)"/>';
                                     	break;
                                     case "1":
                                         return "审核通过";
                                         break;
                                     case "2":
                                         return "审核拒绝";
                                         break;
                                     case "-1":
                                         return "";
                                         break;
                                 	}
                             	}
                            }],
                            sortname: 'status asc,ctime',
                           	sortorder: 'desc',
                            rownumbers: true,
                            jsonReader: {
                                root: 'rows',
                                page: "page",
                                total: 'total',
                                records: "records",
                                repeatitems: false
                            },
                            pager: "#jqGrid_paper",
                            viewrecords: false,
                            hidegrid: false,
                            loadComplete: function(){
                        		var re_records = Number($("#jqGrid").getGridParam('records'));
                        		var page = Number($("#jqGrid").getGridParam('page'));
                        		var rows=Number($("#jqGrid").getGridParam('rowNum'));
                        		var num = re_records-(page-1)*rows;
                        		if(num < rows)
                        		{
                        			for(var i=num;i<rows;i++){
                        				$("#jqGrid").jqGrid("addRowData",(i+1),
                                				{ "SID":"", "CTIME":"", "INSTALLUNITID":"", "AUNAME":"","TEL":"","COMM":"","STATUS":"-1","AUSERNAME":"-1","ATIME":"","STATUS":"-1"}
                        				,"");
                        			}
                        			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
                        		}
                        	}
                        });
            });


    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    
    function refuse(sid,status){
	   	$.post("${pageContext.request.contextPath}/admin/tusers_audit.action", {
	   		'sid': sid,
	   		'status': status,
	   		'communityId':'${communityId}',
   			'agtCode':'${agtCode}'
         }, function (result) {
             result = JSON.parse(result)
             if (result.code == 1 || result.code == 2) {
                 layer.closeAll();
                 refreshGrid();
             } 
             layer.alert(result.msg);
         });
   	 }
    
    function showpic(content) {
        var html = '<img style="margin-left: -18px;" width="960px" src="' + content + '" alt="附件详情"/>';
        layer.open({
            title: '',
            btn: 0,
            area: ['960px', '95%'],
            content: html
        });
    }
    function audit(sid,roomStatus){
    	layer.closeAll();
    	layer.open({
            type: 2,
            title: '<strong>门禁钥匙</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['800px', '600px'],
            content: '${pageContext.request.contextPath}/admin/tusers_selectKeysView.action?communityId=${communityId}&agtCode=${agtCode}&sid='+sid+'&roomStatus='+roomStatus,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
            	var valu = $("#layui-layer-iframe" + index).contents().find("#sure").html();
            	if(valu =='first'){
            		layer.load(2);
	            	$("#layui-layer-iframe" + index).contents().find("#sure").html("again");
	            	$("#layui-layer-iframe" + index).contents().find("#sure").click();
              }else{
                	layer.alert("正在处理中，请稍后提交。如遇长时间处理，请刷新重试。");
                }
            	
//                 $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
//                 $("#layui-layer-iframe" + index).contents().find("#form").submit();
            }
        });
    }

    function approve(sid){
    	layer.open({
            type: 2,
            title: '<strong>住户审核</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', '450px'],
            skin: 'btn-calss',
            content: '${pageContext.request.contextPath}/admin/tusers_approve.action?communityId=${communityId}&agtCode=${agtCode}&sid='+sid,
            btn: ['拒绝', '通过'],
            yes: function(index,layero){
            	refuse(sid,2);
            	},
            btn2: function(index,layero){
          	  var options = {
                      success: function (data) {
                    	  layer.closeAll('loading');
                          data = JSON.parse(data);
                          if (data.code == 1) {
                              layer.alert(data.msg, function () {
                                  layer.closeAll();
                              });
                          } else {
                              layer.alert(data.msg);
                          }
                          refreshGrid();
                      }
                  };
              layer.load(2);
              $("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
         	  $("#layui-layer-iframe" + index).contents().find("#form").submit();  
            }
        });
    };
	if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;
    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
};

</script>
</body>
</html>
